package com.prs.crm.action.document;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.document.DraftFlow;
import com.prs.crm.domain.document.DraftFlowType;
import com.prs.crm.service.document.DraftFlowService;
import com.prs.crm.service.document.DraftFlowTypeService;

public class DraftFlowAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private DraftFlow draftFlow;
	private DraftFlowService draftFlowService;
	
	private PaginationSupport pagination;
	private  Integer[] ids;
	private List<DraftFlowType> draftFlowType;
	private DraftFlowTypeService draftFlowTypeService;
	public DraftFlow getDraftFlow() {
		return draftFlow;
	}
	public void setDraftFlow(DraftFlow draftFlow) {
		this.draftFlow = draftFlow;
	}
	public DraftFlowService getDraftFlowService() {
		return draftFlowService;
	}
	public void setDraftFlowService(DraftFlowService draftFlowService) {
		this.draftFlowService = draftFlowService;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public List<DraftFlowType> getDraftFlowType() {
		return draftFlowType;
	}
	public void setDraftFlowType(List<DraftFlowType> draftFlowType) {
		this.draftFlowType = draftFlowType;
	}
	public DraftFlowTypeService getDraftFlowTypeService() {
		return draftFlowTypeService;
	}
	public void setDraftFlowTypeService(DraftFlowTypeService draftFlowTypeService) {
		this.draftFlowTypeService = draftFlowTypeService;
	}
	@Action("listDraftFlow")
	public String listDraftFlow(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(DraftFlow.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getDraftFlowService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editDraftFlow")
	public String editDraftFlow(){
		this.draftFlowType=this.getDraftFlowTypeService().getAllDraftFlowType();
		return SUCCESS;
	}
	@Action(value="saveDraftFlow",results={
			@Result(name="success",type="redirect",location="listDraftFlow"),
			@Result(name="error",type="chain",location="editDraftFlow")
	})
	public String saveDraftFlow(){
		this.getDraftFlowService().save(draftFlow);
		return SUCCESS;
	}
	@Action(value="removeDraftFlow",results={
			@Result(name="success",type="redirect",location="listDraftFlow"),
			@Result(name="error",type="chain",location="listDraftFlow")
	})
	public String removeDraftFlow(){
		if (ids==null) {
			this.setPrompt("请选择一行！");
			return ERROR;
		}
		this.getDraftFlowService().batchRemove(ids);
		return SUCCESS;
	}
}
